<template>
  <SysDialog draggable :title="dialog.title" :visible="dialog.visible" :width="dialog.width" :height="dialog.height"
    @onClose="onClose" @onConfirm="confirm">
    <template v-slot:content>
      <!-- 内容组件 -->
      <el-form :model="dialogModel" ref="addUserForm" :rules="rules" label-width="120px" size="default">
        <el-form-item prop="name" label="用户姓名">
          <el-input v-model="dialogModel.name" clearable></el-input>
        </el-form-item>
        <el-form-item prop="username" label="用户登录名">
          <el-input v-model="dialogModel.username" clearable></el-input>
        </el-form-item>
        <el-form-item prop="password" label="登录密码">
          <el-input v-model="dialogModel.password" clearable type="password" show-password></el-input>
        </el-form-item>
        <el-form-item prop="gender" label="用户性别">
          <!-- <el-input v-model="dialogModel.gender" clearable></el-input> -->
          <el-select v-model="dialogModel.gender" clearable placeholder="请选择性别" style="width: 100%;">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>

        <el-form-item prop="email" label="用户邮箱">
          <el-input v-model="dialogModel.email" clearable></el-input>
        </el-form-item>
        <el-form-item prop="phone" label="手机号">
          <el-input v-model="dialogModel.phone" clearable></el-input>
        </el-form-item>
        <el-form-item prop="departmentId" label="职位">
          <el-input v-model="dialogModel.departmentId" clearable></el-input>
        </el-form-item>
        <el-form-item prop="positionId" label="部门">
          <el-input v-model="dialogModel.positionId" clearable></el-input>
        </el-form-item>
      </el-form>
    </template>
  </SysDialog>
</template>

<script setup lang='ts'>
import { reactive, toRefs, onBeforeMount, ref, onMounted } from 'vue'
import { EditType, Title } from '@/type/BaseEnum'
import { ElForm } from 'element-plus'
import SysDialog from '@/components/SysDialog.vue';
import useDialog from '@/hooks/useDialog';
import useInstance from '@/hooks/useInstance';
import useAddEdit from '@/composables/03organization/01user/useAddEdit'
// 使用
const addUserForm = ref<InstanceType<typeof ElForm>>();
const { dialog, onClose, onShow } = useDialog()
const { global, proxy } = useInstance();
const { rules, dialogModel, options } = useAddEdit()
// // 父级数据
// const props = defineProps({

// })
// 保存
const emit = defineEmits(['save'])
const confirm = () => {
  addUserForm?.value?.validate((isOk) => {
    if (isOk) {
      emit('save', dialogModel)
      onClose()
    }
  })
}
const show = (type: string, row?: any) => {
  dialog.width = 650
  dialog.height = 400
  // dialog.title = '新增用户'
  dialog.title = type == EditType.ADD ? Title.ADD : Title.EDIT
  onShow()
  global.$resetForm(addUserForm.value, dialogModel)

  if (type === EditType.EDIT) {
    global.$objCopy(row, dialogModel)
  }
}
defineExpose({
  show
})
</script>
<style scoped lang='scss'></style>